package com.yujn.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.stereotype.Component;

/**
 * 创建一个自定义的过滤器工厂类，
 * 继承自AbstractNameValueGatewayFilterFactory。
 * 这个类将解析配置文件中的参数，并在请求处理过程中添加指定的参数到 JSON 入参中
 */
@Slf4j
@Component
public class AddRequestJsonParamGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {

    @Override
    public GatewayFilter apply(NameValueConfig config) {
        return (exchange, chain) -> {
            // 省略添加逻辑，先简单点
            log.info("AddRequestJsonParamGatewayFilterFactory==="
                    + config.getName() + ":" + config.getValue());
            return chain.filter(exchange);
        };
    }
}
